package com.token.iot.bratterycharging.gateway.business;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.outstanding.framework.core.PendingException;
import com.token.iot.bratterycharging.gateway.IDGeneration;
import com.token.iot.bratterycharging.gateway.api.Constant;
import com.token.iot.bratterycharging.gateway.utils.ByteUtil;

/**
 * 设置功率比例饿
 * 
 * @author chenzhixuan
 *
 */
@Component("CHMDuplexProcessor")
public class CHMDuplexProcessor extends DuplexProcessor {

	@Override
	public String request(String imei, Map<String, String> params) throws PendingException {
		String sessionId = IDGeneration.createSeesionID();
		String command = null;

		String powver1 = params.get(Constant.POWER1);
		String ratio1 = params.get(Constant.RATIO1);
		command = code + sessionId + "/" + powver1+ratio1;
		
		String powver2 = params.get(Constant.POWER2);
		String ratio2 = params.get(Constant.RATIO2);
		command = command + powver2+ratio2;
		
		String powver3= params.get(Constant.POWER3);
		String ratio3 = params.get(Constant.RATIO3);
		command = command + powver3+ratio3;
		
		
		String powver4 = params.get(Constant.POWER4);
		String ratio4 = params.get(Constant.RATIO4);
		command = command + powver4+ratio4;
		
		
		String powver5 = params.get(Constant.POWER5);
		String ratio5 = params.get(Constant.RATIO5);
		command = command + powver5+ratio5;
		
		loger.info("the send =" + new String(command));
		byte[] cc = ByteUtil.addFlag(command.getBytes());
		context.writeAndFlush(cc);
		return sessionId;

	}

	@Override
	public Boolean response(String response) throws PendingException {
		String val = response.substring(14);
		if ("1".equals(val)) {
			return true;
		} else {
			return false;
		}

	}

}